package com.jt.demo3;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Component
@Aspect
@EnableAspectJAutoProxy
public class DemoAspect {

    @Around("bean(userServiceImpl)")
    public Object around(ProceedingJoinPoint joinPoint) {

        long l = System.currentTimeMillis();
//        Object proceed=null;
//        try {
//            proceed = joinPoint.proceed();
//        }catch (Exception E){
//            E.printStackTrace();
//        }
        Object proceed = null;
        try {
            proceed = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        long l1 = System.currentTimeMillis();
        System.out.println(l1-l);
        Class<?> aClass = joinPoint.getTarget().getClass();
        String declaringTypeName = joinPoint.getSignature().getDeclaringTypeName();
        String name = joinPoint.getSignature().getName();
        System.out.println(aClass);
        System.out.println(declaringTypeName);
        System.out.println(name);
        return proceed;
    }
    @AfterThrowing(value = "execution(* com.jt.demo3.service..*.*(..))",throwing = "e")
    public void AfterThrowing(Exception e){
        e.printStackTrace();
        System.out.println(e.getMessage());
    }
}
